/*
 * Copyright 2012 Alan Burlison, alan@bleaklow.com.  All rights reserved.
 * Use is subject to license terms.  See LICENSE.txt for details.
 */

/*
 * LIS302DL accelerometer.
 * Hard-coded to use INT0 for data ready detection
 */

#ifndef LIS302DL_h
#define LIS302DL_h

#include <avr/interrupt.h>
#include "Task.h"
#include "SPIMaster.h"

#define AVG_NUM 50

class LIS302DL : public SPIMaster , public Task {
public:
    // Acceleration data.
    struct XYZ {
        int8_t x;
        int8_t y;
        int8_t z;
    };
    enum Mode { Disabled, Absolute, Relative };
    LIS302DL(const pin_t *const _csn);
    virtual void initPins(bool shared);
    void setMode(Mode mode);
    virtual bool canRun(uint32_t now);
protected:
    uint8_t readRegister(uint8_t reg);
    void writeRegister(uint8_t reg, uint8_t val);
    void waitForData(void);
    void readData(XYZ *xyz);
};

#endif
